package cn.edu.scau.cmi.yangzhichao.abstractFactory;

import cn.edu.scau.cmi.yangzhichao.abstractFactory.domainAbstractClass.*;
import cn.edu.scau.cmi.yangzhichao.abstractFactory.factory.InsuranceFactory;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.text.Font;

/**
 * Created by yzc on 2019/3/23.
 */
public class InsuranceView3Controller {
    private String nameString;
    private String optionsString;
    private Insurance insurance;
    @FXML
    private TextArea textArea;
    @FXML
    private ComboBox comboBox;
    @FXML
    private ComboBox comboBox1;
    @FXML
    private void initialize(){
        ObservableList<String> name= FXCollections.observableArrayList("中国人寿保险","平安保险");
        ObservableList<String> options= FXCollections.observableArrayList("身体受伤","车损坏","人员伤亡","多种事故");
        comboBox.setItems(name);
        comboBox1.setItems(options);
        textArea.setFont(Font.font("宋体",20));
        nameString="中国人寿保险";
        optionsString="身体受伤";
        comboBox.valueProperty().addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                nameString=(String)newValue;
                handleSubmit();
            }
        });
        comboBox1.valueProperty().addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                optionsString=(String)newValue;
                handleSubmit();
            }
        });
    }
    @FXML
    public void handleSubmit(){
        InsuranceFactory factory=InsuranceFactory.getFactory(nameString);
        switch (optionsString){
            case "身体受伤":{
                insurance=factory.createBodyInsurance();
            }break;
            case "车损坏":{
                insurance=factory.createCarInsurance();
            }break;
            case "人员伤亡":{
                insurance=factory.createHurtInsurance();
            }break;
            case "多种事故":{
                insurance=factory.createTypesInsurance();
            }break;
        }
        textArea.setText(insurance.getMessage());
    }
}
